package com.istock.union.user.service.impl;

import org.springframework.beans.factory.annotation.Autowired;

import com.istock.base.serializer.json.TypeReference;
import com.istock.union.user.client.SSOClientUtils;
import com.istock.union.user.model.SSOUser;
import com.istock.union.user.service.StorageService;
import com.istock.union.user.service.TokenService;

public class TokenServiceImpl implements TokenService {

	@Autowired
	private StorageService storageService;
	
	public void setStorageService(StorageService storageService) {
		this.storageService = storageService;
	}
	
	public StorageService getStorageService() {
		return storageService;
	}

	@Override
	public SSOUser verify(String token) {
		return findTokenModel(token);
	}
	
	public SSOUser findTokenModel(String token) {
		String tokenKey = SSOClientUtils.KEY_TOKEN+token;
		return storageService.getObject(token , tokenKey, new TypeReference<SSOUser>() {});
	}
}
